package com.rtx.api.config;

import com.alibaba.fastjson.JSON;
import com.rtx.api.bean.ApiResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionConfig {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 处理异常
     */
    @ExceptionHandler(Exception.class)
    public ApiResponse handleException(Exception ex) {
        logger.error("全局异常：", ex);
        return ApiResponse.failed().msg(ex == null ? "处理异常" : ex.getMessage());
    }
}
